﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

/// <summary>
///PersonalInformation 的摘要说明
/// </summary>
public class PersonalInformation
{
	public PersonalInformation()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}

    //判断个人信息输入是否合法，写入数据库是否成功弹出提示信息。
    public static void AddPersenalInformation(string sUserName, string sBirthday, string sSex, string sTelPhone)
    { 
        if (sTelPhone.Length <= 11)
        {
            //构造SQL语句
            string sqlCommend = "UPDATE User SET Birthday=" + sBirthday + ",Sex=" + sSex + ",TelNumber=" + sTelPhone
                +"WHERE UserName=" + sUserName;
			DataBaseClass.Update(sqlCommend, DataBaseClass.GetConnectionString());
        }
    }

    //查询并返回用户的用户名。该函数通过判断传入的字符串是用户名或邮箱来查询用户的信息并填入数组返回。
    public static string[] ShowUserInformation(string sSearchString)
    { 
        //声明大小为3的字符数组，该函数返回该数组
        string[] m_sarUserInfo = new string[3];

        //构造SQL语句
        string[] att = {"UserName","Email","RegDate"};
        string cond;
        string table = "User";

        //根据传入参数的不同构造不同的SQL语句
        if (sSearchString.Contains("@"))//如果用户通过邮箱登陆
            cond = "Email=" + sSearchString;
        else
            cond = "UserName" + sSearchString;

        //选取数据库中的用户名、邮箱、注册时间
        DataTable dt = new DataTable();
        dt = DataBaseClass.selectData(att, cond, table, DataBaseClass.GetConnectionString());

        //取出数据填充到数组中
        if (dt.Rows.Count != 0)
        {
            m_sarUserInfo[0] = dt.Rows[0]["UserName"].ToString();
            m_sarUserInfo[1] = dt.Rows[0]["Email"].ToString();
            m_sarUserInfo[2] = dt.Rows[0]["RegDate"].ToString();
        }
        //如果穿出数组的第一个空为空，则显示出错
        return m_sarUserInfo;
    }
}